package com.ldl.servlet.admin;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ldl.dto.Search;
import com.ldl.entity.Ldl;
import com.ldl.service.LdlService;
import com.ldl.service.impl.LdlServiceImpl;

/**
 * @author Administrator
 * Author : L.D.L
 * E-mail : 1419485293@qq.com
 * Date : 2020年7月24日下午8:35:47
 */
public class LdlListServlet extends HttpServlet{

	private LdlService ldlService = new LdlServiceImpl();
	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int current = 1;
		try{
			current = Integer.valueOf(request.getParameter("current"));
		}catch(Exception ex){
			
		}
		int len = 10;
		try{
			len = Integer.valueOf(request.getParameter("len"));
		}catch(Exception ex){
			
		}
		
		
		Search search = new Search();
		search.setPageNumber(current);
		String key = request.getParameter("key");
		if(key==null){
			key = "";
		}
		search.setPageSize(len);
		search.setKey(key);
		
		int total = ldlService.count(key);
		request.setAttribute("total", total);
		
		List<Ldl> list = ldlService.search(search.getKey(), current, len);
		request.setAttribute("search", search);
		request.setAttribute("p", list);
		request.getRequestDispatcher("/admin/ldl-list.jsp").forward(request, response);
	}
}
